<!DOCTYPE HTML>
<html lang="en-US">
<head>
  <meta charset="UTF-8">
  <title>Automaster Planning Tool</title>
  <link rel="stylesheet" href="Assets/css/bootstrap.css" type="text/css" media="screen" title="no title" charset="utf-8">
  <link rel="stylesheet" href="Assets/css/custom.css" type="text/css" media="screen" title="no title" charset="utf-8">
  <link rel="stylesheet" href="Assets/js/dojo/dijit/themes/claro/Dialog.css" type="text/css" media="screen" title="no title" charset="utf-8">
 
  <script type="text/javascript" charset="utf-8">
    var storedata = {};
  </script>

  <script src="Assets/testdata/2.0/dates.js"></script>
  <script src="Assets/testdata/2.0/resources.js"></script>
  <script src="Assets/testdata/2.0/reservations.js"></script>
  <script src="Assets/testdata/2.0/departments.js"></script>
  <script src="Assets/testdata/2.0/breaks.js"></script>
  <script src="Assets/testdata/2.0/shifts.js"></script>

  <script>
  dojoConfig = {
    isDebug: true,
    packages: [ { name: "apt", location: "../../apt" } ]
  }
  </script>

  <script type="text/javascript" src="Assets/js/dojo/dojo/dojo.js"></script>
  <script type="text/javascript" src="Assets/testdata/testdata.js"></script>

  <script type="text/javascript" charset="utf-8">

  Date.prototype.getMonthName = function() {
    var m = ['January','February','March','April','May','June','July',
    'August','September','October','November','December'];
    return m[this.getMonth()];
  } 
  Date.prototype.getDayName = function() {
    var d = ['Sunday','Monday','Tuesday','Wednesday',
    'Thursday','Friday','Saturday'];
    return d[this.getDay()];
  }
  Date.prototype.getWeek = function() {
    var onejan = new Date(this.getFullYear(),0,1);
    return Math.ceil((((this - onejan) / 86400000) + onejan.getDay()+1)/7);
  }
  String.prototype.toDateFromAspNet = function() {
    // TODO: This does not account for timezones.
    var dateStr = this.replace(/[\/Date\(\)]/g, '').replace(/(\+.*)/g, '');
    var date = new Date( parseInt(dateStr) );
    // date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
    return date;
  };
  String.prototype.toDateFromAspNetFormated = function() {
    var d = this.toDateFromAspNet();
    var month;
    var day;
    if (d.getMonth() + 1 < 10) {
      month = '0' + (d.getMonth() + 1);
    } else {
      month = d.getMonth() + 1;
    }
    if (d.getDate() < 10) {
      day = '0' +  d.getDate();
    } else {
      day = d.getDate();
    }
    return d.getFullYear() + "-" + month + "-" + day;
  };

	String.prototype.parseISO8601 = function() {
		var parts, dateParts, timeParts, timeSubParts, timeSecParts, timeHours, divider;

		divider = (this.indexOf('T') != -1) ? 'T' : ' ';

		parts = this.split(divider);
		dateParts = parts[0].split('-');
		
		if (parts[1].indexOf('Z') != -1){
			timeParts = parts[1].split('Z');			
		} else if (parts[1].indexOf('+') != -1){
			timeParts = parts[1].split('+');
		} else if (parts[1].indexOf('-') != -1){
			timeParts = parts[1].split('-');
		} else {
			timeParts = [parts[1]];
		}
		
		timeSubParts = timeParts[0].split(':');
 
		timeHours = Number(timeSubParts[0]),
		
		_date = new Date;	
		_date.setFullYear(Number(dateParts[0]));
		_date.setMonth(Number(dateParts[1])-1);
		_date.setDate(Number(dateParts[2]));
		_date.setHours(Number(timeHours));
		_date.setMinutes(Number(timeSubParts[1]));

		if (timeSubParts[2]) {
			timeSecParts = timeSubParts[2].split(".");
			_date.setSeconds(Number(timeSecParts[0]));			
		}
		if (timeSecParts[1]) _date.setMilliseconds(Number(timeSecParts[1]));	
		if (timeSubParts[3]) _date.setMilliseconds(Number(timeSubParts[3]));	
		// by using setUTC methods the date has already been converted to local time(?)
		return _date;
 };
  </script>

</head>
<body>

  <div class="wrap">

    <div id="ptloading" class="alert alert-info" style="position: absolute; left: 20px; right: 20px; top: 20px; bottom: 20px;">
      <table style="height: 100%;" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td style="text-align: center; vertical-align: middle;">
            <h1>Planning Tool loading</h1>
            <br>
            <img src="Assets/img/spinner.gif">
          </td>
        </tr>
      </table>
    </div>

    <div id="pt">
      &nbsp;
    </div>
  </div>


  <script type="text/javascript" charset="utf-8">

    dojo.ready(function(){
      dojo.require('apt.PlanningTool');      
    });
    
    setTimeout(function(){ window.pt = new apt.PlanningTool({elementHeight: 44}, 'pt'); }, 10); //options,elementID))
  </script>
</body>
</html>